import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)
export default new Vuex.Store({
  namespace:true,
  state: {
    token:'',
    userInfo:null,
  },
  mutations: {
    // set
    SET_TOKEN:(state,token) =>{
      state.token = token
      localStorage.setItem("token",token)
    },
    SET_USERINFO:(state,userInfo) =>{
      state.userInfo = userInfo
      sessionStorage.setItem("userInfo",JSON.stringify(userInfo))
    },
    SET_REMOVE:(state) =>{
      state.token = ''
      state.userInfo = {}
      localStorage.setItem("token",'')
      sessionStorage.setItem("userInfo",'')
    }
  },
  getters:{
    // get
    getUser: state => {
      if (state.userInfo !=null){
        return state.userInfo
      }else {
        return null;
      }
    }
  },
  actions: {},
  modules:{}
})
